package com.LGF.Book.biz;

import com.LGF.Book.bean.BookType;
import com.LGF.Book.dao.BookTypeDao;

import java.sql.SQLException;
import java.util.List;

public class BookTypeBiz {

    //创建BookTypeDao对象
    BookTypeDao bookTypeDao = new BookTypeDao();

    /**
     * 调用dao层根据类型名称获取图书类型信息
     * @param tname
     * @return
     */
    public BookType getByTname(String tname){
        BookType bookType = null;
        try {
            bookType = bookTypeDao.getByTname(tname);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return bookType;

    }

    /**
     * 调用dao层根据类型名模糊查询图书类型信息
     * @param tname
     * @return
     */
    public List<BookType> selectTName(String tname){
        List<BookType> bookTypeList = null;
        try {
            bookTypeList = bookTypeDao.selectTName(tname);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return bookTypeList;
    }

    /**
     * 调用dao层分页查询图书类型信息
     * @param page
     * @param limit
     * @return
     */
    public List<BookType> getByPage(int page,int limit){
        List<BookType> bookTypeList = null;
        try {
            bookTypeList = bookTypeDao.getByPage(page, limit);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return bookTypeList;
    }

    /**
     * 获取所有图书类型信息
     * @return
     */
    public List<BookType> getAll(){
        List<BookType> bookTypeList = null;
        try {
            bookTypeList = bookTypeDao.getAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return bookTypeList;
    }

    /**
     * 调用dao层根据id查询图书类型信息
     * @param id
     * @return
     */
    public BookType getById(long id){
        BookType bookType = null;
        try {
            bookType = bookTypeDao.getById(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return bookType;
    }

    /**
     * 调用dao层添加图书类型信息
     * @param tname
     * @return
     */
    public int add(String tname){
        int count = 0;
        try {
            count = bookTypeDao.add(tname);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return count;
    }

    /**
     * 调用dao层修改图书类型信息
     * @param id
     * @param tname
     * @return
     */
    public int modify(long id,String tname){
        int count = 0;
        try {
            count = bookTypeDao.modify(id, tname);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return count;


    }

    /**
     * 调用dao层根据id删除图书类型信息
     * @param id
     * @return
     */
    public int remove(long id){
        int count = 0;
        try {
            count = bookTypeDao.remove(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return count;

    }
}
